// This File is part of the "GmailNotifier2" Project
// 
// Copyright  2009 sometmes@gmail.com
// All rights reserved
// 
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace Notify2
{
    class PreviewMenuItem : ToolStripMenuItem // ToolStripItem
    {
        int lineHeight = 22;

        public int LineHeight
        {
            get { return lineHeight; }
            set { lineHeight = value; }
        }

        string textHeader;

        public string TextHeader
        {
            get { return textHeader; }
            set { textHeader = value; }
        }

        string textContent;

        public string TextContent
        {
            get { return textContent; }
            set { textContent = value; }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            if (this.Text != "")
                throw new ArgumentException("'Text' property should be empty");

            if (base.Owner != null)
            {
                ToolStripRenderer renderer = this.Owner.Renderer;
                Graphics g = e.Graphics;
                renderer.DrawMenuItemBackground(new ToolStripItemRenderEventArgs(g, this));
                Color textColor = SystemColors.MenuText;

                //if (this.Selected || this.Pressed)
                //{
                //    textColor = SystemColors.HighlightText;
                //}
                //else
                //{
                //    textColor = SystemColors.MenuText;
                //}

                Color previewColor = Color.FromArgb(Math.Min(255, textColor.R + 150), Math.Min(255, textColor.G + 150), Math.Min(255, textColor.B + 150));

                if ((this.DisplayStyle & ToolStripItemDisplayStyle.Text) == ToolStripItemDisplayStyle.Text)
                {
                    renderer.DrawItemText(new ToolStripItemTextRenderEventArgs(g, this
                        //, "x: " + this.textRectangle.X + "owner: " + this.Owner.Size.Width + "twidth: " + this.textRectangle.Width + "iwidth: " + this.Size.Width
                        , this.TextHeader
                        , textRectangle
                        , textColor, this.Font, TextFormatFlags.EndEllipsis));

                    TextRenderer.DrawText(g, this.TextContent, this.Font, text2Rectangle, previewColor
                        , TextFormatFlags.WordBreak);
                }
            }
        }

        Rectangle textRectangle;
        Rectangle text2Rectangle;
        protected override void SetBounds(Rectangle bounds)
        {
            if (base.Owner != null)
            {
                this.textRectangle = new Rectangle(bounds.X, 0, bounds.Width - bounds.X, lineHeight);

                text2Rectangle = new Rectangle(this.textRectangle.Location, new Size(this.textRectangle.Width, bounds.Height - lineHeight));
                text2Rectangle.Offset(0, lineHeight);
            }
            base.SetBounds(bounds);
        }

    }
}
